using Microsoft.AspNetCore.Mvc;
using RemiseANiveau2.Models;
using System.Reflection;

namespace RemiseANiveau2.Controllers
{
    public class Autre : Controller
    {
        /// <summary>
        /// Retourne "bonjour"
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            var model = new AutreIndexViewModel();

            return View(model);
        }
     

        /// <summary>
        /// Retourne "bonjour"
        /// </summary>
        /// <returns></returns>
        public IActionResult Calcul()
        {
            return View(new AutreCalculViewModel());
        }

        /// <summary>
        /// Retourne la valeur du calcul des deux paramètres passés 
        /// </summary>
        /// <param name="id"></param>
        /// <returns>id+id2;</returns>
        [HttpPost]
        public IActionResult Calcul(AutreCalculViewModel model)
        {
            string TypeCalcul = model.TypeCalcul;
            double Resultat = 0;
            double Numero2 = model.Numero2;
            double Numero1 = model.Numero1;
            if (TypeCalcul == "Addition")
            {
                Resultat = Numero1 + Numero2;
            }
            else if (TypeCalcul == "Soustraction")
            {
                Resultat = Numero1 - Numero2;

            }
            else if (TypeCalcul == "Multiplication")
            {
                Resultat = Numero1 * Numero2;
            }
            else if (TypeCalcul == "Division")
            {
                Resultat = Numero1 / Numero2;

            }
          
            model.Resultat = Resultat;

            return View(model);
        }
    }
}
